package Lee_code;

import java.util.ArrayList;
import java.util.List;

/**
 * @author blh
 * @date 2024年09月09日 10:08
 */
public class Lee_986_99 {
    public int[][] intervalIntersection(int[][] firstList, int[][] secondList) {
        int firLen = firstList.length;
        int sedLen = secondList.length;

        int m = 0, n = 0;
        List<int[]> list = new ArrayList<>();

        while (m < firLen && n < sedLen) {
            int[] firTemp = firstList[m];
            int[] secTemp = secondList[n];
            int left = Math.max(firTemp[0], secTemp[0]);
            int right = Math.min(firTemp[1], secTemp[1]);
            if (right >= left) {
                list.add(new int[]{left, right});
            }
            if (firTemp[1] >= secTemp[1]) {
                n++;
            } else {
                m++;
            }
        }
        return list.toArray(new int[][]{new int[list.size()]});
    }

    public static void main(String[] args) {
        Lee_986_99 method = new Lee_986_99();
        int[][] first = new int[][]{{1, 5}, {8, 12}, {15, 24}, {25, 26}};
        int[][] second = new int[][]{{0, 2}, {5, 10}, {13, 23}, {24, 25}};
        int[][] ints = method.intervalIntersection(first, second);
        for (int[] anInt : ints) {

        }
    }
}
